public class Solution {
    public boolean isRowValid(char[][] board, int row) {
        int[] a = new int[10];
        for(int i = 0; i < 9; i++) {
            int t = board[row][i];
            if(t != '.') {
                if(a[t - '0'] == 1) {
                    return false;
                } else {
                    a[t - '0'] = 1;
                }
            }
        }
        return true;
    }

    public boolean isColValid(char[][] board, int col) {
        int[] a = new int[10];
        for(int i = 0; i < 9; i++) {
            int t = board[i][col];
            if(t != '.') {
                if(a[t - '0'] == 1) {
                    return false;
                } else {
                    a[t - '0'] = 1;
                }
            }
        }
        return true;
    }

    public boolean isBlockValid(char[][] board, int sr, int sc) {
        int[] a = new int[10];
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                int t = board[sr + i][sc + j];
                if(t != '.') {
                    if(a[t - '0'] == 1) {
                        return false;
                    } else {
                        a[t - '0'] = 1;
                    }
                }
            }
        }
        return true;
    }

    public boolean isValidSudoku(char[][] board) {
        for(int i = 0; i < 9; i++) {
            if(!isRowValid(board, i)) {
                return false;
            }
            if(!isColValid(board, i)) {
                return false;
            }
        }
        for(int i = 0; i < 9; i += 3) {
            for(int j = 0; j < 9; j += 3) {
                if(!isBlockValid(board, i, j)) {
                    return false;
                }
            }
        }
        return true;
    }
}